package com.gyyweishang.controller;

import com.gyyweishang.pojo.Emp;
import com.gyyweishang.pojo.LoginInfo;
import com.gyyweishang.pojo.Result;
import com.gyyweishang.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private EmpService empService;

    @PostMapping //@RequestBody 表示接收json格式的数据，@RequestParam 表示接收普通参数
    public Result login(@RequestBody Emp emp) {
        log.info("登录接收信息：{}", emp);
        LoginInfo login = empService.login(emp);
        if (login != null) {
            return Result.success(login);
        }
        return Result.error("用户名或密码错误");
    }
}
